package com.baselibrary.test.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.View.bar.initAction_Bar;
import com.baselibrary.libs.View.defined.defined_listView.Defined_listView;
import com.baselibrary.libs.View.pullableview.PullToRefreshLayout.MyListener;
import com.baselibrary.libs.base.baseActivity.BaseActivity;
import com.baselibrary.libs.design_mode.DesignModeActivity;
import com.baselibrary.libs.example.example_listView.bean.itemData;
import com.baselibrary.libs.example.example_listView.interfaces.listViewCallBack;
import com.baselibrary.test.MVP.MainActivity.contract.MainContract;
import com.baselibrary.test.MVP.MainActivity.presenter.MainPresenter;
import com.baselibrary.test.R;
import com.baselibrary.test.app.AppContext;
import com.baselibrary.test.servers.DemoIntentService;
import com.igexin.sdk.PushManager;

import java.util.ArrayList;

public class MainActivity extends BaseActivity implements MainContract.View {

    private initAction_Bar action_bar;
    private MainPresenter mPresenter;
    private Defined_listView mDefined_listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // com.getui.demo.DemoIntentService 为第三方自定义的推送服务事件接收类
       // PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), DemoIntentService.class);
       // PushManager.getInstance().initialize(this.getApplicationContext(), DemoPushService.class);
        // com.getui.demo.DemoIntentService 为第三方自定义的推送服务事件接收类
        PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), DemoIntentService.class);



    }



    @Override
    public int getlayouXML() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {

        action_bar = (initAction_Bar) findViewById(R.id.action_bar);

        mDefined_listView = (Defined_listView)findViewById(R.id.defined_listView);
        initData();
    }



    @Override
    public void initP() {
        mPresenter = new MainPresenter(this);
    }

    @Override
    public void initData() {
        action_bar.set_Title("主页");

        mPresenter.getData();
    }

    @Override
    public void initListener() {

    }
    //双击退出程序
    private long firstPressTime = 0;
    @Override
    public void onBackPressed() {
        long now = System.currentTimeMillis();
        if ((now - firstPressTime) > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            firstPressTime = now;
        } else {
            finish();
            //System.exit(0);
        }
    }

    @Override
    public void ListData_success(ArrayList<itemData> itemDatas) {
        mDefined_listView.initListData(AppContext.getApplication(), 0, itemDatas, new listViewCallBack() {
            @Override
            public void CallBackCilckItem(int postion) {
                LogUtils.i("我点了"+postion);
                switch (postion){
                        case 0:
                            startActivity(new Intent(AppContext.getApplication(),viewpager_fragment_pull_01.class));
                        break;
                        case 1:
                            startActivity(new Intent(AppContext.getApplication(),viewpager_fragment_pull_02.class));
                        break;
                        case 2:
                            startActivity(new Intent(AppContext.getApplication(),Main2Activity.class));
                        break;
                        case 3:
                            startActivity(new Intent(AppContext.getApplication(),Main3Activity.class));
                        break;
                        case 4:
                            startActivity(new Intent(AppContext.getApplication(),Main4Activity.class));
                        break;
                        case 5:
                            startActivity(new Intent(AppContext.getApplication(),DesignModeActivity.class));
                        break;
                        case 6:
                            startActivity(new Intent(AppContext.getApplication(),Main6Activity.class));
                        break;
                        case 7:
                            startActivity(new Intent(AppContext.getApplication(),Main7Activity.class));
                        break;
                        case 8:
                            startActivity(new Intent(AppContext.getApplication(),Main8Activity.class));
                        break;
                        case 9:
                            startActivity(new Intent(AppContext.getApplication(),Main9Activity.class));
                        break;
                        case 10:
                            startActivity(new Intent(AppContext.getApplication(),Main10Activity.class));
                        break;
                        case 11:
                            startActivity(new Intent(AppContext.getApplication(),Main11Activity.class));
                        break;
                        case 12:
                            startActivity(new Intent(AppContext.getApplication(),Main12Activity.class));
                        break;
                        case 13:
                            startActivity(new Intent(AppContext.getApplication(),Main13Activity.class));
                        break;
                        case 14:
                            startActivity(new Intent(AppContext.getApplication(),Main14Activity.class));
                        break;

                }
            }
        });

        mDefined_listView.initListener(new MyListener());
    }

    @Override
    public void ListData_failure(String s) {

    }
}
